/* juchang.com.js - producer: leo [13141414820] - time: 2010.2.2 - QQ: 978817604 - www.miaov.com */

$(function(){

    // header
    (function(){
        var text = $("#header").find(".text");
        var txt  = text.attr("value");
        var btn  = $("#btn");
        text.focus(function(){ $(this).select(); if($(this).attr("value") == txt ){ $(this).attr("value", ""); }; });
        btn.hover(function(){ $(this).attr("class","btn_active"); },function(){ $(this).attr("class","btn_normal"); });
		
		var text_foot = $("#search_foot").find(".text");
		var txt_foot  = text_foot.attr("value");
		var btn_foot  = $("#btn_foot");
        text_foot.focus(function(){ $(this).select(); if($(this).attr("value") == txt_foot ){ $(this).attr("value", ""); }; });
        btn_foot.hover(function(){ $(this).attr("class","btn_active"); },function(){ $(this).attr("class","btn_normal"); });

		var text_topbar = $("#topbar").find(".text");
		var txt_topbar  = text_topbar.attr("value");
		var small_btn  = $("#small_btn");
        text_topbar.focus(function(){ $(this).select(); if($(this).attr("value") == txt_topbar ){ $(this).attr("value", ""); }; });
        small_btn.hover(function(){ $(this).attr("class","btn_active"); },function(){ $(this).attr("class","btn_normal"); });
    })();

    // nav
    (function(){
        $("#nav li:last").attr("class", "");
        $("#nav li").find(".active").parent().prev().attr("class", "");
        $("#nav li").hover(function(){
            if( $(this).find("a").attr("class") != "active" ) { $(this).prev().attr("class", ""); };
        },function(){
            if( $(this).find("a").attr("class") != "active" ) { $(this).prev().attr("class", "line");  };
        });
    })();

    // tab
    (function(){
        Tab("tab1", "mouseover");
        Tab("tab2", "mouseover");
        Tab("tab3", "mouseover");
		Tab("tab4", "click");
        function Tab( object , evt ){
            var obj = $("#"+object);
            var li  = obj.find(".tab_btn").find("li");
            var box = obj.find(".tab_box");
            box.hide().eq(0).show();
            li.bind(evt , function(){ var num = li.index($(this)); li.attr("class","normal").eq(num).attr("class","active"); box.hide().eq(num).show(); });
        };
    })();

    // scroll
    (function(){
        Scroll("#scrollOne" , 3000);
        Scroll("#scrollTwo" , 3000);
        Scroll("#scrollThree" , 3000);
        function Scroll( obj , ms ){
            var box = $(obj).find(".box");
            var ul = box.find("ul");
            var posX = ul.width()/2;
            var num = 0;
            var control = $(obj).find(".control");
            var timer;
            ul.css({"width": ul.find("li").width()*ul.find("li").length*2+"px","position":"absolute","top":0,"left":0});
            function play(){
                timer = setInterval(function(){
                    if(num%2 == 1){
                        ul.animate({left: -posX + "px"},ms/2);
                        control.find("li").eq(0).attr("class","prev_active");
                        control.find("li").eq(1).attr("class","normal");
                        control.find("li").eq(2).attr("class","active");
                        control.find("li").eq(3).attr("class","next");
                    }else{
                        ul.animate({left: 0 + "px"},ms/2);
                        control.find("li").eq(0).attr("class","prev");
                        control.find("li").eq(1).attr("class","active");
                        control.find("li").eq(2).attr("class","normal");
                        control.find("li").eq(3).attr("class","next_active");
                    };
                    num++;
                    if(num > 2){num = 1;};
                }, ms);
            };
            play();
            control.find("li").eq(0).click(function(){
                clearInterval(timer);
                ul.stop().animate({left: -posX + "px"},ms/3);
                control.find("li").eq(0).attr("class","prev_active");
                control.find("li").eq(1).attr("class","normal");
                control.find("li").eq(2).attr("class","active");
                control.find("li").eq(3).attr("class","next");
                play();
            });
            control.find("li").eq(3).click(function(){
                clearInterval(timer);
                ul.stop().animate({left: 0 + "px"},ms/3);
                control.find("li").eq(0).attr("class","prev");
                control.find("li").eq(1).attr("class","active");
                control.find("li").eq(2).attr("class","normal");
                control.find("li").eq(3).attr("class","next_active");
                play();
            });
        };
    })();
	
	// bear_fruit_list
	(function(){
		var pic = $(".bear_fruit_list").find(".pic");		
		pic.hover(function(){
			$(this).siblings(".synopsis").show();
		},function(){
			$(this).siblings(".synopsis").hide();
		});
		
		var details = $(".bear_fruit_list").find(".details");
		var obj;
		var box;
		var li;
		var js_scroll;
		var next;
		var prev;
		var thisClose;
		var ff_bug;
		var w_val;
		
		function play(){			
			prev.click(function(){	
				var thisBox = $(this).siblings(".js_scroll").find(".box");
				if( thisBox.position().left >= 0  ){
					thisBox.animate({left: 0 + "px" });	
					return false;
				};
				thisBox.stop().animate({left: "+=" + ff_bug + "px" });			
			});
			next.click(function(){	
				var thisBox = $(this).siblings(".js_scroll").find(".box");
				if( Math.abs(thisBox.position().left)+ff_bug >= w_val-ff_bug ){
					thisBox.animate({left: -w_val+js_scroll.innerWidth() + "px" });	
					return false;
				};
				thisBox.stop().animate({left: "-=" + ff_bug + "px" });			
			});
		};

		details.click(function(){
			$(this).parents(".li").find(".sum").show();
			
			 obj = $(this).parents(".li").find(".num");
			 box = obj.find(".box");
			 li = box.find("li");
			 js_scroll = obj.find(".js_scroll");
			 next = obj.find(".next");
			 prev = obj.find(".prev");
			 thisClose = obj.find(".close");
			 ff_bug = 200;
			 w_val = li.innerWidth()*li.length + ff_bug;
			 
			 box.css("width",  w_val + "px");
		
			if( box.innerWidth()-ff_bug > js_scroll.innerWidth() ) {
				next.show();
				prev.show();
			};
			box.animate({left: 0 + "px" });	
			play();
			closeFn();
			
		});
		
		function closeFn(){
			thisClose.click(function(){
				$(this).parents(".sum").hide();
			});
		};
		
	})();

});